﻿#region File Description
//-----------------------------------------------------------------------------
// Circle.cs
//
// Attack of the Crazy Pixels
// Copyright (c) 2009 VosSoft
//-----------------------------------------------------------------------------
#endregion
#region License
//-----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2009 VosSoft
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace Attack_of_the_Crazy_Pixels
{
    /// <summary>
    /// Defines a circle.
    /// </summary>
    public class Circle : Polygone
    {
        public Vector2 Center { get; private set; }
        public float Radius { get; private set; }

        /// <summary>
        /// Creates a polygon in the shape of a circle.
        /// </summary>
        /// <param name="center">The offset of the center of the circle.</param>
        /// <param name="radius">The radius of the circle.</param>
        /// <param name="segments">The number of segments used in the circle.</param>
        /// <param name="dashed">Draw the circle with a dashed outline.</param>
        /// <param name="rotation">Rotation of the (dashed) Circle (in radians).</param>
        public Circle(Vector2 center, float radius, int segments, bool dashed, float rotation)
            : this(center, radius, segments, dashed, rotation, 1.0f, Color.Black)
        {
        }

        /// <summary>
        /// Creates a polygon in the shape of a circle.
        /// </summary>
        /// <param name="center">The offset of the center of the circle.</param>
        /// <param name="radius">The radius of the circle.</param>
        /// <param name="segments">The number of segments used in the circle.</param>
        /// <param name="dashed">Draw the circle with a dashed outline.</param>
        /// <param name="rotation">Rotate the dashed Circle (in radians).</param>
        /// <param name="thickness">Thickness of the outline.</param>
        /// <param name="color">Color of the outline.</param>
        public Circle(Vector2 center, float radius, int segments, bool dashed, float rotation, float thickness, Color color)
        {
            points = new Vector2[segments];
            if (dashed)
            {
                lines = new Line[segments / 2];
            }
            else
            {
                lines = new Line[segments];
            }
            float angle = MathHelper.TwoPi / segments;

            for (int i = 0; i < segments; i++)
            {
                points[i] = new Vector2(
                    center.X + radius * (float)Math.Sin(angle * i + rotation),
                    center.Y + radius * (float)Math.Cos(angle * i + rotation));
            }
            if (dashed)
            {
                for (int i = 0; i < segments / 2; i++)
                {
                    lines[i] = new Line(points[i * 2], points[i * 2 + 1], thickness, color);
                }
            }
            else
            {
                for (int i = 0; i < segments - 1; i++)
                {
                    lines[i] = new Line(points[i], points[i + 1], thickness, color);
                }
                lines[segments - 1] = new Line(points[segments - 1], points[0], thickness, color);
            }

            Thickness = thickness;
            Color = color;
            Center = center;
            Radius = radius;
        }
    }
}
